<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Robocup-denayer-project-a: read-only/trunk/source/thread.cpp Bron Bestand</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javaScript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Gegenereerd door Doxygen 1.7.1 -->
<script type="text/javascript"><!--
var searchBox = new SearchBox("searchBox", "search",false,'Zoeken');
--></script>
<script type="text/javascript">
function hasClass(ele,cls) {
  return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}

function addClass(ele,cls) {
  if (!this.hasClass(ele,cls)) ele.className += " "+cls;
}

function removeClass(ele,cls) {
  if (hasClass(ele,cls)) {
    var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
    ele.className=ele.className.replace(reg,' ');
  }
}

function toggleVisibility(linkObj) {
 var base = linkObj.getAttribute('id');
 var summary = document.getElementById(base + '-summary');
 var content = document.getElementById(base + '-content');
 var trigger = document.getElementById(base + '-trigger');
 if ( hasClass(linkObj,'closed') ) {
   summary.style.display = 'none';
   content.style.display = 'block';
   trigger.src = 'open.png';
   removeClass(linkObj,'closed');
   addClass(linkObj,'opened');
 } else if ( hasClass(linkObj,'opened') ) {
   summary.style.display = 'block';
   content.style.display = 'none';
   trigger.src = 'closed.png';
   removeClass(linkObj,'opened');
   addClass(linkObj,'closed');
 }
 return false;
}
</script>
<div class="navigation" id="top">
  <div class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Hoofd&nbsp;Pagina</span></a></li>
      <li><a href="annotated.html"><span>Klassen</span></a></li>
      <li class="current"><a href="files.html"><span>Bestanden</span></a></li>
      <li id="searchli">
        <div id="MSearchBox" class="MSearchBoxInactive">
          <span class="left">
            <form id="FSearchBox" action="search.php" method="get">
              <img id="MSearchSelect" src="search/mag.png" alt=""/>
              <input type="text" id="MSearchField" name="query" value="Zoeken" size="20" accesskey="S" 
                     onfocus="searchBox.OnSearchFieldFocus(true)" 
                     onblur="searchBox.OnSearchFieldFocus(false)"/>
            </form>
          </span><span class="right"></span>
        </div>
      </li>
    </ul>
  </div>
  <div class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&nbsp;Lijst</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;members</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<h1>read-only/trunk/source/thread.cpp</h1>  </div>
</div>
<div class="contents">
<a href="thread_8cpp.html">Ga naar de documentatie van dit bestand.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
<a name="l00010"></a>00010 <span class="preprocessor">#include &lt;pthread.h&gt;</span>
<a name="l00011"></a>00011 <span class="preprocessor">#include &lt;iostream&gt;</span>
<a name="l00012"></a>00012 <span class="preprocessor">#include &quot;<a class="code" href="thread_8h.html">thread.h</a>&quot;</span>
<a name="l00013"></a>00013 
<a name="l00014"></a>00014 <span class="keyword">using namespace </span>std;
<a name="l00015"></a>00015 
<a name="l00016"></a>00016 <span class="keyword">extern</span> <span class="stringliteral">&quot;C&quot;</span>
<a name="l00017"></a>00017 {
<a name="l00018"></a>00018     <span class="comment">// this C function will be used to receive the thread and pass it back to the Thread instance</span>
<a name="l00019"></a><a class="code" href="thread_8cpp.html#af49f7d3d7fb40559930dce6c487247ad">00019</a>     <span class="keywordtype">void</span>* <a class="code" href="thread_8cpp.html#af49f7d3d7fb40559930dce6c487247ad">thread_catch</a>(<span class="keywordtype">void</span>* arg) {
<a name="l00020"></a>00020         <a class="code" href="class_thread.html" title="Thread.">Thread</a>* t = <span class="keyword">static_cast&lt;</span><a class="code" href="class_thread.html" title="Thread.">Thread</a>*<span class="keyword">&gt;</span>(arg);
<a name="l00021"></a>00021         t-&gt;<a class="code" href="class_thread.html#afbb442f2fb941af397f840d6f9ef55a2" title="Thread::execute();.">execute</a>();
<a name="l00022"></a>00022         <span class="keywordflow">return</span> 0;
<a name="l00023"></a>00023     }
<a name="l00024"></a>00024 }
<a name="l00025"></a>00025 
<a name="l00026"></a>00026 
<a name="l00035"></a><a class="code" href="class_thread.html#a1f53ee62bd30a7924186ef26150ce262">00035</a> <span class="keywordtype">void</span> <a class="code" href="class_thread.html#a1f53ee62bd30a7924186ef26150ce262" title="Thread::start();.">Thread::start</a>() {
<a name="l00036"></a>00036     pthread_create(&amp;handle, 0, <a class="code" href="thread_8cpp.html#af49f7d3d7fb40559930dce6c487247ad">thread_catch</a>, <span class="keyword">this</span>);
<a name="l00037"></a>00037 }
<a name="l00038"></a>00038 
<a name="l00047"></a><a class="code" href="class_thread.html#afbb442f2fb941af397f840d6f9ef55a2">00047</a> <span class="keywordtype">void</span> <a class="code" href="class_thread.html#afbb442f2fb941af397f840d6f9ef55a2" title="Thread::execute();.">Thread::execute</a>() {
<a name="l00048"></a>00048     cout &lt;&lt; <span class="stringliteral">&quot;Thread:Hello From a new Thread!&quot;</span> &lt;&lt; endl;
<a name="l00049"></a>00049 }
<a name="l00058"></a><a class="code" href="class_thread.html#abb98d8920ffd8d7e05affe68014cafea">00058</a> <span class="keywordtype">void</span> <a class="code" href="class_thread.html#abb98d8920ffd8d7e05affe68014cafea" title="Thread::wait_for_exit();.">Thread::wait_for_exit</a>() {
<a name="l00059"></a>00059     pthread_join(handle, NULL);
<a name="l00060"></a>00060 }
<a name="l00061"></a>00061 
<a name="l00067"></a><a class="code" href="thread_8h.html#a2fa7d525ff3fefb8266255563ae8896b">00067</a> <span class="keywordtype">int</span> <a class="code" href="thread_8cpp.html#a2fa7d525ff3fefb8266255563ae8896b" title="Probeer de lock op object te krijgen.">mutex_lock</a>(pthread_mutex_t* __mutex){
<a name="l00068"></a>00068     <span class="keywordtype">int</span> r = pthread_mutex_trylock(__mutex);
<a name="l00069"></a>00069 
<a name="l00070"></a>00070     <span class="keywordflow">if</span>(r != 0)
<a name="l00071"></a>00071     {
<a name="l00072"></a>00072         cout &lt;&lt; <span class="stringliteral">&quot;Mutex_Lock Mislukt!: &quot;</span> &lt;&lt; r &lt;&lt; endl;
<a name="l00073"></a>00073         <span class="keywordflow">return</span> pthread_mutex_lock(__mutex);
<a name="l00074"></a>00074     }
<a name="l00075"></a>00075     <span class="keywordflow">else</span>
<a name="l00076"></a>00076         <span class="keywordflow">return</span> r;
<a name="l00077"></a>00077 }
<a name="l00078"></a>00078 
<a name="l00079"></a><a class="code" href="thread_8h.html#ae9cd60f1fa40bbc5b3c312493f0ea89f">00079</a> <span class="keywordtype">int</span> <a class="code" href="thread_8cpp.html#ae9cd60f1fa40bbc5b3c312493f0ea89f">mutex_unlock</a>(pthread_mutex_t* __mutex){
<a name="l00080"></a>00080     <span class="keywordflow">return</span> pthread_mutex_unlock(__mutex);
<a name="l00081"></a>00081 }
</pre></div></div>
</div>
<hr class="footer"/><address class="footer"><small>Gegenereerd op Do 19 Mei 2011 10:15:29 voor Robocup-denayer-project-a door&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.1 </small></address>
</body>
</html>
